import { defineStore } from 'pinia';
import type { ProjectItem } from '@/api/projectList';

export interface ActiveMenu {
	title: string;
	path: string;
}
export interface UserInfo {
	id: string;
	account: string;
}
const useMainStore = defineStore('main', {
	state: () => ({
		// 项目信息
		projectInfo: {
			_id: '',
			code: '',//项目编码
			name: ''//项目名称
		},
		isCollapse: false,//收起菜单
		activeMenu: {//激活的菜单
			title: '',
			path: ''
		},
		routerList: []//动态路由列表
	}),

	getters: {},

	actions: {
		setIsCollapse(val: boolean) {
			this.isCollapse = val;
		},
		setActiveMenu(val: ActiveMenu) {
			this.activeMenu = val;
		},
		setProjectInfo(val: ProjectItem) {
			this.projectInfo = val;
		},
		setRouterList(val: any) {
			this.routerList = val;
		}
	},
	persist: { //持久化配置
		enabled: true,//开启持久化，默认将所有的状态(共享参数)全部存入到session中
		storage: localStorage,
		pick: ['projectInfo', 'isCollapse'],
	}
});

export default useMainStore;
